Here, we run a variety of sensitivity analyses on the original and time-averaged networks. This code has been adapted from Peeples, Matthew A. 2017. Network Science and Statistical Techniques for Dealing with Uncertainties in Archaeological Datasets. [online]. Available: www.mattpeeples.net/netstats.html. One main difference is that we use igraph rather than the sna and network packages.
# First, load in all of the the igraph objects (i.e., Chaco_original_graphs and Chaco_ta_graphs). However, we will only use Chaco_ta_graphs, as the first network for each time period will be the original graph.
load("../Data/Chaco_graph_objects.RData")
# The lists are unnested for 1 level.
Chaco.nets <- purrr::map(Chaco_ta_graphs, 1)
# Give names to each list for each time period to keep track.
chaco.names <- c("chaco800", "chaco825", "chaco850", "chaco875",
"chaco900", "chaco925", "chaco950", "chaco975",
"chaco1000", "chaco1025", "chaco1050", "chaco1075",
"chaco1100", "chaco1125", "chaco1150", "chaco1175",
"chaco1200", "chaco1225", "chaco1250", "chaco1275")
names(Chaco.nets) <- chaco.names
Chaco.ta.num <- purrr::map(Chaco_ta_graphs, 2)
# Further prepare a name list that will be used to rename elements in a list for plotting (i.e., to have a time period [e.g., chaco800] concatenated to a network number [e.g., chaco800_network_1]).
chaco.net.names <- as.data.frame(chaco.names) %>%
replicate(n = length(Chaco.nets), simplify = FALSE) %>%
unlist() %>%
as.data.frame() %>%
dplyr::rename(period = 1)
chaco.net.names$period <-
factor(chaco.net.names$period, levels = chaco.names)
chaco.net.names <-
chaco.net.names[order(chaco.net.names$period), ] %>%
as.data.frame() %>%
dplyr::rename(period = 1)
chaco.net.names$period <- as.character(chaco.net.names$period)
network.names <- as.data.frame(paste("network", unlist(Chaco.ta.num), sep = "_")) %>%
dplyr::rename(network = 1)
chaco.net.names.full <- cbind(chaco.net.names, network.names)
chaco.net.names.full <- chaco.net.names.full %>%
tidyr::unite(period_network, c("period", "network"))
#Next (for additional setup for outputting plots into pdfs), get the total number of networks (the chaco 20 time averaged networks per time period for a total of 400). Then, create a sequence, which will be used as an index to extract 3 ggplot objects per time period.
Chaco.num.net.seq <- Chaco.ta.num %>%
unlist() %>%
as.data.frame() %>%
dplyr::rename("graphs" = 1) %>%
dplyr::mutate(index = 1:length(graphs)) %>%
dplyr::mutate(chaco.net.names)
# Get rows with the maximum graphs for each period.
net.seq.max <- Chaco.num.net.seq %>%
group_by(period) %>%
slice(which.max(graphs))
# Get rows with the minimum graphs (i.e., the original).
net.seq.min <- Chaco.num.net.seq %>%
group_by(period) %>%
slice(which.min(graphs))
# Function for finding the middle value.
which.median <- function(x) ceiling(max(x)/2)
# Get rows with the median amount of graphs.
net.seq.median <- Chaco.num.net.seq %>%
group_by(period) %>%
slice(which.median(graphs))
net.seq.full <- rbind(net.seq.max, net.seq.min, net.seq.median) %>%
arrange(index) %>%
ungroup() %>%
dplyr::select(index) %>%
unlist()
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'orig.net', 'num.net'. You can override using the `.groups` argument.
## Saving 10.5 x 7.5 in image